package com.itheima.app.mq;

import com.itheima.domain.mongo.Video;
import com.itheima.domain.mongo.VideoScore;
import com.itheima.service.mongo.VideoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

@Component
@SuppressWarnings("all")
public class VideoScoreMQSend {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @DubboReference
    private VideoService videoService;
    public static final Integer VIDEO_PUBLISH = 1;// 发视频
    public static final Integer VIDEO_BROWSE = 2;// 浏览视频
    public static final Integer VIDEO_LIKE = 3;// 点赞
    public static final Integer VIDEO_COMMENTSLiIKE = 4;// 评论点赞
    public static final Integer VIDEO_COMMENT = 5;// 评论
    public static final Integer VIDEO_DISLIKE = 6;// 取消点赞
    public static final Integer VIDEO_DISCOMMENTSLiIKE = 7;// 取消评论点赞

    public void sendVideo(Long userId, ObjectId videoId, Integer type) {
        VideoScore videoScore = new VideoScore();
        videoScore.setDate(System.currentTimeMillis());
        videoScore.setUserId(userId);
        Video video = videoService.findVideoById(videoId);
        videoScore.setVideoId(video.getVid());

        switch (type) {
            case 1: {
                videoScore.setScore(20d);
                break;
            }
            case 2: {
                videoScore.setScore(1d);
                break;
            }
            case 3: {
                videoScore.setScore(5d);
                break;
            }
            case 4: {
                videoScore.setScore(8d);
                break;
            }
            case 5: {
                videoScore.setScore(10d);
                break;
            }
            case 6: {
                videoScore.setScore(-5d);
                break;
            }
            case 7: {
                videoScore.setScore(-8d);
                break;
            }
        }
        rocketMQTemplate.convertAndSend("recomment-video",videoScore);
    }
}
